package cn.wolfcode.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JWTUtils {
    private static String singeKey = "wolfcode";
    private static Long expiration = 3600L * 24 * 3600L;

    public static String generateToken(Map<String, Object> map) {
        return Jwts.builder().addClaims(map).signWith(SignatureAlgorithm.HS256, singeKey)
                .setExpiration(new Date(System.currentTimeMillis() + expiration)).compact();
    }

    public static Claims parserToken(String token) {
        return Jwts.parser().setSigningKey(singeKey).parseClaimsJws(token).getBody();
    }
}
